package quanlydoanvao.themmoi;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import quanlydoanra.utils.truyXuatDatabase;
import utils.DateUtils;
import dbutil.ConnectDB;

public class VanBanNhan {
	private int id;
	private String soUBNDTinh;
	private java.util.Date ngayPhatHanhVB;
	private boolean baoCao;
	private String nguoiChuTri;
	private String moTaQD;
	
	public VanBanNhan() {
	}

	public VanBanNhan(String soUBNDTinh, Date ngayPhatHanhVB, boolean baoCao,
			String nguoiChuTri, String moTaQD) {
		this.soUBNDTinh = soUBNDTinh;
		this.ngayPhatHanhVB = ngayPhatHanhVB;
		this.baoCao = baoCao;
		this.nguoiChuTri = nguoiChuTri;
		this.moTaQD = moTaQD;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getSoUBNDTinh() {
		return soUBNDTinh;
	}

	public void setSoUBNDTinh(String soUBNDTinh) {
		this.soUBNDTinh = soUBNDTinh;
	}

	public java.util.Date getNgayPhatHanhVB() {
		return ngayPhatHanhVB;
	}

	public void setNgayPhatHanhVB(java.util.Date ngayPhatHanhVB) {
		this.ngayPhatHanhVB = ngayPhatHanhVB;
	}

	public boolean isBaoCao() {
		return baoCao;
	}

	public void setBaoCao(boolean baoCao) {
		this.baoCao = baoCao;
	}

	public String getNguoiChuTri() {
		return nguoiChuTri;
	}

	public void setNguoiChuTri(String nguoiChuTri) {
		this.nguoiChuTri = nguoiChuTri;
	}

	public String getMoTaQD() {
		return moTaQD;
	}

	public void setMoTaQD(String moTaQD) {
		this.moTaQD = moTaQD;
	}

	public int insertVBNhan(){
		try{
		java.sql.Date sqlDate =  DateUtils.utilDateToSqlDate(this.ngayPhatHanhVB);	
		String sql2 = "insert into vanbannhan(soubndtinh,ngayphathanh,baocao,nguoichutri, motaqd) values('"+this.soUBNDTinh+"','"+sqlDate+"',"+this.baoCao+",'"+this.nguoiChuTri+"','"+this.moTaQD+"')";
		System.out.println(sql2);
		int idVBNhan = truyXuatDatabase.insertData(sql2);
		
		if(idVBNhan == 1){
			String sql1 = "select * from vanbannhan where soubndtinh = '"+this.soUBNDTinh+"' and ngayphathanh = '"+this.ngayPhatHanhVB+"'";
			ArrayList arr = ConnectDB.getDataTypeList(sql1);
			HashMap<String, Object> hash = (HashMap<String, Object>) arr.get(0);
			int id = Integer.parseInt(hash.get("id").toString());
			System.out.println("id VB nhan"+id);
			this.id = id;
		}
		}
		catch(Exception ex){
			System.out.println("Loi ");
		}
	return this.id;
	}
	public static void main(String[] args) {
		VanBanNhan vb = new VanBanNhan();
		vb.setSoUBNDTinh("123");
		vb.setNgayPhatHanhVB(DateUtils.sqlDateToutilDate(java.sql.Date.valueOf("2008-4-5")));
		vb.setBaoCao(true);
		vb.setNguoiChuTri("AAA");
		vb.setMoTaQD("mno ta ");
	
	}
}
